package sim;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.LinkedList;
import java.util.zip.GZIPInputStream;

import matrics.SparseVector;
import myLucene.GetTime;

public class ReadObject {

	/**
	 * @param args
	 */
	public static LinkedList<Integer>[] readLinkedListArray(String fileName)
			throws IOException, ClassNotFoundException {
		// Read from disk using FileInputStream
		System.out.println("Start readLinkedListArray");
		long start = System.currentTimeMillis();
		FileInputStream f_in = new FileInputStream(fileName);

		GZIPInputStream gz_in = new GZIPInputStream(f_in);
		ObjectInputStream obj_in = new ObjectInputStream(gz_in);

		// Read an object
		Object obj = obj_in.readObject();

		// if (obj instanceof int[][]) {
		// Cast object to a Vector
		// int[][] ar = (int[][]) obj;
		// Do something with vector....
		// for (int i = 0; i <2; i++) {
		// for( int x =0 ; x < 3; x++){
		// System.out.println(ar[i][x]);
		// }
		// }
		if (obj instanceof LinkedList<?>[]) {
			// Cast object to a Vector
			LinkedList<Integer>[] ar = (LinkedList<Integer>[]) obj;
			System.out.println("Read LINKEDLIST Time needed: "
					+ GetTime.getDuration(start, System.currentTimeMillis()));

			return ar;

		} else {
			System.out.println("Reading Error: ReadObject.readLinkedListArray");
			return null;
		}

	}

	public static int[] readArray(String fileName) throws IOException,
			ClassNotFoundException {
		// Read from disk using FileInputStream
		System.out.println("Start readArray");
		long start = System.currentTimeMillis();
		FileInputStream f_in = new FileInputStream(fileName);
		// Read object using ObjectInputStream

		GZIPInputStream gz_in = new GZIPInputStream(f_in);
		ObjectInputStream obj_in = new ObjectInputStream(gz_in);

		// Read an object
		Object obj = obj_in.readObject();

		// if (obj instanceof int[][]) {
		// Cast object to a Vector
		// int[][] ar = (int[][]) obj;
		// Do something with vector....
		// for (int i = 0; i <2; i++) {
		// for( int x =0 ; xfacebook < 3; x++){
		// System.out.println(ar[i][x]);
		// }
		// }
		if (obj instanceof int[]) {
			// Cast object to a Vector
			int[] ar = (int[]) obj;
			System.out.println("Read ARRAY Time needed: "
					+ GetTime.getDuration(start, System.currentTimeMillis()));

			return ar;

		} else {
			System.out.println("Reading Error: ReadObject.readArray");
			return null;
		}

	}
	public static SparseVector[] readSparseVectorArray(String fileName) throws IOException,
	ClassNotFoundException {
// Read from disk using FileInputStream
System.out.println("Start readArray");
long start = System.currentTimeMillis();
FileInputStream f_in = new FileInputStream(fileName);
// Read object using ObjectInputStream

GZIPInputStream gz_in = new GZIPInputStream(f_in);
ObjectInputStream obj_in = new ObjectInputStream(gz_in);

// Read an object
Object obj = obj_in.readObject();

// if (obj instanceof int[][]) {
// Cast object to a Vector
// int[][] ar = (int[][]) obj;
// Do something with vector....
// for (int i = 0; i <2; i++) {
// for( int x =0 ; xfacebook < 3; x++){
// System.out.println(ar[i][x]);
// }
// }
if (obj instanceof SparseVector[]) {
	// Cast object to a Vector
	SparseVector[] ar = (SparseVector[]) obj;
	System.out.println("Read ARRAY Time needed: "
			+ GetTime.getDuration(start, System.currentTimeMillis()));

	return ar;

} else {
	System.out.println("Reading Error: ReadObject.readArray");
	return null;
}

}

}
